<template>
  <div class="con">
    <div class="contbox6_10" v-if="type == 1">
      <p
        class="titlelist6_10 titles"
        style="box-shadow: none; position: fixed; z-index: 5"
      >
        采购管理
        <span style="color: #999; font-size: 16px">&nbsp;&nbsp; <span style="font-size: 16px; color: #2f2c29">/</span>
          &nbsp;&nbsp; </span>政策列表
      </p>
      <div class="content">
        <div class="sousuojg6_10">
          <el-form ref="form" :model="form" label-width="80px">
            <div>
              <el-form-item label="政策名称" style="float: left" v-if="false">
                <el-input
                  v-model="form.policyName"
                  style="width: 200px"
                  
                ></el-input>
              </el-form-item>
              <el-form-item label="政策标识" style="float: left">
                <el-input
                  v-model="form.policyCode"
                  style="width: 200px"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="有效期状态"
                class="youxiao"
                style="float: left; width: 90px"
              >
                <el-select
                  v-model="form.dateStatus"
                  clearable
                  placeholder="请选择类型"
                >
                  <el-option label="全部" value=""></el-option>
                  <el-option label="未开始" value="0"></el-option>
                  <el-option label="使用中" value="1"></el-option>
                  <el-option label="已失效" value="2"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="状态" style="float: left">
                <el-select
                  v-model="form.status"
                  clearable
                  placeholder="请选择类型"
                >
                  <el-option label="全部" value=""></el-option>
                  <el-option label="启用" value="0"></el-option>
                  <el-option label="停用" value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="政策日期" style="float: left">
                <el-date-picker
                  class="time"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="开始日期"
                  v-model="form.startDate"
                ></el-date-picker>
                <div class="times">至</div>
                <el-date-picker
                  class="time"
                  v-model="form.endDate"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="结束日期"
                ></el-date-picker>
              </el-form-item>
            </div>
            <div class="clearfix"></div>
          </el-form>
        </div>
        <div>
          <div class="boxer">
            <el-button
              v-if="isAuth('policySearch')"
              type="primary"
              @click="onSubmit"
              >搜索</el-button>
            <el-button v-if="isAuth('policyReset')" @click="rest">重置</el-button>
            <el-button icon="el-icon-plus" v-if="isAuth('createPolicy')" @click="createPolicy" type="primary" plain style="margin-left:35px"
              >创建政策</el-button>
          </div>
        </div>

        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          :header-cell-style="{ background: '#F9FAFC', color: '#222' }"
          stripe
          border
          :row-style="{ height: '0px' }"
          :cell-style="{ padding: '0px' }"
          style="width: 98%; margin-left: 20px"
        >
          <el-table-column
            v-if="false"
            prop="typeName"
            label="商品类型"
            min-width="150"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="policyName"
            label="政策名称"
            v-if="false"
            min-width="150"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="policyCode"
            label="政策标识"
            min-width="150"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="beginDate"
            label="开始时间"
            min-width="160"
          ></el-table-column>
          <el-table-column
            prop="endDate"
            label="结束时间"
            min-width="160"
          ></el-table-column>

          <el-table-column
            label="使用状态"
            min-width="80"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <div v-if="scope.row.status == 0">启用</div>
              <div v-if="scope.row.status == 1">停用</div>
            </template>
          </el-table-column>
          <el-table-column
            label="有效期状态"
            min-width="100"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <div v-if="scope.row.dateStatus == 0">未开始</div>
              <div v-if="scope.row.dateStatus == 1">使用中</div>
              <div v-if="scope.row.dateStatus == 2">已失效</div>
            </template>
          </el-table-column>
          <el-table-column label="操作" min-width="260" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-button
                type="text"
                v-if="isAuth('policyDetail')"
                @click="catDetail(scope.row)"
                >查看</el-button
              >
              <el-button
                type="text"
                v-if="isAuth('policyChange')"
                @click="setInfo(scope.row)"
              >
                修改
              </el-button>
              <el-button
                type="text"
                @click="changeStatus(scope.row)"
                v-if="scope.row.status == 1 && isAuth('policyUpdate')"
              >
                启用
              </el-button>
              <el-button
                type="text"
                @click="changeStatus(scope.row)"
                v-if="scope.row.status == 0 && isAuth('policyUpdate')"
              >
                <span style="color: #f56c6c">停用</span>
              </el-button>
              
            </template>
          </el-table-column>
        </el-table>
        <div></div>
        <el-pagination
          style="text-align: right"
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="form.page"
          :page-sizes="[20, 50, 100]"
          :page-size="form.number"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalPage"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
//引入归属机构;
import https from "../../plugins/https"
import { CompareDate } from "../../assets/js/commion";
import Tree from "../tree/index";
export default {
  name: "route",
  data() {
    return {
      // 控制弹出框
      dialogVisible: false,
      // 取消弹框
      dialogVisible1: false,
      mechanismAdd: false,
      mechanismDetails: false,
      mechanismBsiness: false,
      readonly: true,
      typebox: 0,
      treeBool: false,
      showType: false,
      type: 1,
      mechanism: "",
      currentPage: 1, //默认显示第一页
      pageSize: 10, //默认每页显示10条
      totalNum: 0, //总页数
      msg: [],
      memberTypsText: "",
      memberType: [
        {
          value: "",
          label: "全部",
        },
        {
          value: "0",
          label: "OEM",
        },
        {
          value: "1",
          label: "普通代理",
        },
      ],
      // 列表ordercode
      orderCode: "",
      // value: '',
      newType: "",
      checkedAll: false,
      // 审核意见
      examineVal: "",
      // 取消原因
      cancelVeason: "",
      // 审核批量
      examineArr: [],
      // 总共几页
      totalPage: "",

      form: {
        dateStatus: "",
        policyName: "",
        policyCode: "", //政策标识
        // productType:"",//产品类型
        typeName: "", //产品类型
        status: "", //政策状态
        startDate: "", //开始时间
        endDate: "", //结束时间
        page: 1,
        number: 20,
      },
      tableData: [],
      multipleSelection: [],
      //   urltype: this.GLOBAL.httpurl,
    };
  },
  created() {
    this.getList();
  },
  mounted() {},

  components: {
    Tree,
  },
  methods: {
    // 创建
    createPolicy(){
      this.$router.push({
        name:"createPolicy"
      })
    },
    // 下面是分页
    handleSizeChange(val) {
      this.form.number = val;
      this.getList();
    },
    // 切换页数
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList();
    },
    //发送请求获取列表数据
    getList() {
      https.getPurchaseList(this.form).then((res) => {
          this.tableData = res.data.data;
          this.totalPage = res.data.total;
        })
        .catch((err) => {
        });
    },
    // 点击查看
    catDetail(val) {
      let id = val.id;
      let policyCode = val.policyCode;
      this.$router.push({
        name: "policyDetail",
        query: {
          id: id,
          policyCode: policyCode,
        },
      });
    },
    // 搜索
    onSubmit() {
      if (this.form.startDate != "" && this.form.endDate != "") {
        if (CompareDate(this.form.startDate, this.form.endDate)) {
          this.form.page = 1;
          this.getList();
        } else {
          layer.open({
            content: "开始时间不能小于结束时间",
            skin: "msg",
            time: 2, //2秒后自动关闭
          });
        }
      } else {
        this.form.page = 1;
        this.getList();
      }
    },
    // 重置
    rest() {
      this.form.page = 1;
      this.form.policyCode = "";
      this.form.typeName = "";
      this.form.status = "";
      this.form.startDate = "";
      this.form.endDate = "";
      this.form.policyName = "";
      this.form.dateStatus = "";
      this.getList();
    },
    // 停用启用
    changeStatus(val) {
      let id = val.id;
      https.policyStop({ id: id })
        .then((res) => {
          console.log(res);
          this.getList();
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 修改
    setInfo(val){
      this.$router.push({
        name:"createPolicy",
        query:{
          id:val.id,
          policyCode:val.policyCode
        }
      })
    }
  },
};
</script>

<style scoped>
/deep/ .el-container[data-v-4d4a7ce2] {
  background: #f5f7fa !important;
  height: 100% !important;
}
.con {
  position: relative;
}
/* 单独样式 */
.contbox6_10 {
  width: 100%;
  position: relative;
  /*  height: 87.5vh; */
  overflow-x: auto;
  box-sizing: border-box;
  float: left;
}
.titlelist6_10 {
  position: absolute;
  padding-left: 20px;
  height: 40px;
  background: #fff;
  width: 100%;
  float: left;
  line-height: 40px;
  font-size: 16px;
  color: #222;
  box-shadow: 0px 0px 12px #c0c4cc;
}
.content {
  float: left;
  margin-top: 200px;
  margin-bottom: 0px;
  margin: 36px 0px 0px;
  height: calc(100vh - 100px - 26px);
  background: #fff;
}
.buttons {
  width: 100%;
  float: left;
  border: none;
  margin-bottom: 10px;
}
.buttons .el-button {
  float: left;
  padding: 7px;
}
.el-form-item {
  margin-bottom: 10px;
}
/* .el-input__inner {
  width: 300px;
} */
.time {
  width: 136px !important;
}
.time > .el-input__inner {
  width: 100% !important;
}
.times {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.el-col-1 {
  width: 3%;
}
.nav {
  width: 100%;
  display: flex;
}
.clearfix:after {
  display: block;
  height: 0;
  clear: both;
  content: ".";
  visibility: hidden;
}
.titles {
  font-size: 16px;
  /* font-weight: bold; */
}
/* /deep/ .el-form-item__label {
  color: #909399 !important;
} */
.boxer {
  display: inline-block;
  padding-right: 20px;
  float: left;
  margin-left: 20px;
}
.boxer > .el-button {
  width: 100px;
  padding: 7px;
}
.subTtile {
  font-size: 18px;
  font-weight: bold;
}
.titlesSub {
  font-size: 18px;
  font-weight: bold;
  width: 80px;
  display: inline-block;
}
/* @media screen and (max-width: 1450px) {
  .el-form-item {
    width: 50% !important;
  }
}
@media screen and (max-width: 1020px) {
  .el-form-item {
    width: 100% !important;
  }
} */
.exports {
  color: #409eff;
  border-color: #409eff;
}
.el-button {
  padding: 0;
}
.reject,
.adopt {
  width: 80px;
  height: 40px;
  background: #fff;
}
.adopt {
  background: #409eff;
  color: white;
}
body{
  overflow-y: hidden;
}
/deep/ .youxiao .el-form-item__label {
  width: 90px !important;
}
</style>
